package svc.elib.analysis;

import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedList;

import svc.elib.db.Database;
import svc.elib.socnet.CentralityMetrics;
import svc.elib.socnet.Link;
import svc.elib.socnet.Net;
import svc.elib.socnet.SocConstructor;
import svc.elib.util.Distribution;

public class LinkNodeBetDistr {
	
	private Net net;
	private CentralityMetrics cm;
	
	public LinkNodeBetDistr(Net net) {
		this.net = net;
		cm = new CentralityMetrics(net);
		cm.computeBetweeness(false);
	}

	public void linkDistr() {
		LinkedList<Integer> val = new LinkedList<Integer>();
		Iterator<Link> lit = net.getGraph().getEdges().iterator();
		while (lit.hasNext()) {
			Link l = lit.next();
			int b = (int) cm.getLinkBetweenness(l.getName());
			val.add(b);
		}
		
		System.out.println("\n\nDistribution of link betweeness");
		Distribution d = new Distribution(val);
		d.printDistr();
		System.out.println("Complementary cummulative distribution... ");
		d.printComplementaryCumulative();
	}

	public static void main(String[] args) 
		throws IOException
	{
		Database db = new Database("eLibData.csv", 1932, 2011);
		SocConstructor soc = new SocConstructor(db);
		Net net = soc.getNet();
		LinkNodeBetDistr d = new LinkNodeBetDistr(net);
		d.linkDistr();
	}
	
}
